﻿Imports Newtonsoft.Json

Public Class BiometricsManager

    Private manager As SQLManager

    Public Sub New()
        manager = New SQLManager
    End Sub

    Public Function getHoursWorked(ByVal emp As Employee, ByVal fromDate As String, ByVal todate As String) As Integer
        Dim hours As Integer = 0



        Return hours
    End Function

    Public Function retrieveFingerPrintCountByEmployeeId(ByVal empId As Integer) As Integer
        Dim empInfoArr As New List(Of Biometrics)

        Dim query As String = "SELECT * FROM `tbl_biometrics` WHERE employee_id='" + empId.ToString + "'"
        Dim resultString As String = "" + manager.executeQuery(query)

        empInfoArr = JsonConvert.DeserializeObject(Of List(Of Biometrics))(resultString)

        Return empInfoArr.Count
    End Function

    Public Function deleteAllFingerPrintByEmployeeId(ByVal empId As Integer) As Boolean


        Dim query As String = "DELETE FROM `tbl_biometrics` WHERE employee_id='" + empId.ToString + "'"
        manager.executeQuery(query)

        Return True
    End Function

    Public Function uploadBio(ByVal bioObj As Biometrics)
        Dim query As String = "INSERT INTO `tbl_biometrics` (`id`, `employee_id`, `template_string`) VALUES (NULL, '" + bioObj.employee_id.ToString + "', '" + bioObj.template_string + "')"
        manager.executeUpdate(query)
    End Function

    Public Function uploadLoginBio(ByVal bioObj As Biometrics)
        Dim query As String = "INSERT INTO log_biometrics (`id`, `employee_id`, `time_log`,`log_type`) VALUES (NULL, '" + bioObj.employee_id.ToString + "' , '" + DateTime.Now.ToString("yyyy-M-d HH:mm:ss") + "','0')"
        manager.executeUpdate(query)
    End Function
    Public Function uploadLogoutBio(ByVal bioObj As Biometrics)
        Dim query As String = "INSERT INTO log_biometrics (`id`, `employee_id`, `time_log`,`log_type`) VALUES (NULL, '" + bioObj.employee_id.ToString + "' , '" + DateTime.Now.ToString("yyyy-M-d HH:mm:ss") + "','1')"
        manager.executeUpdate(query)
    End Function

    Public Function uploadLoginManual(ByVal empId As String)
        Dim query As String = "INSERT INTO log_biometrics (`id`, `employee_id`, `time_log`,`log_type`) VALUES (NULL, '" + empId.ToString + "' , '" + DateTime.Now.ToString("yyyy-M-d HH:mm:ss") + "','0')"
        manager.executeUpdate(query)
    End Function
    Public Function uploadLogoutManual(ByVal empId As String)
        Dim query As String = "INSERT INTO log_biometrics (`id`, `employee_id`, `time_log`,`log_type`) VALUES (NULL, '" + empId.ToString + "' , '" + DateTime.Now.ToString("yyyy-M-d HH:mm:ss") + "','1')"
        manager.executeUpdate(query)
    End Function

    Public Function retrieveLogBio() As List(Of LogBiometrics)
        Dim bioArr As New List(Of LogBiometrics)
        Dim query As String = "SELECT * FROM log_biometrics"
        Dim resultString As String = "" + manager.executeQuery(query)

        bioArr = JsonConvert.DeserializeObject(Of List(Of LogBiometrics))(resultString)

        If (resultString = "") Then
            MsgBox("NO DATA")
        End If
        Return bioArr
    End Function

    Public Function retrieveBio() As List(Of Biometrics)
        Dim bioArr As New List(Of Biometrics)
        Dim query As String = "SELECT * FROM tbl_biometrics"
        Dim resultString As String = "" + manager.executeQuery(query)

        bioArr = JsonConvert.DeserializeObject(Of List(Of Biometrics))(resultString)

        If (resultString = "") Then
            MsgBox("NO DATA")
        End If
        Return bioArr
    End Function



End Class
